package org.cuatrovientos.empirefleet;


import java.util.Scanner;
import java.util.Vector;

/**
 * Represents an imperial fleet composed
 * of many space_ships
 * @author Sienar Fleet Systems
 * @greets the emperor
 */
public class Fleet extends Vector<SpaceShip> {
	String commanderName;
	
	/**
	 * creates fleet
	 * three steps: define commander name, create fleet, show fleet
	 */
	public void create_fleet () {
		Scanner reader = new Scanner(System.in);
		String option = "";
		String name = "";
		
		// Give commander name
		setCommander(reader);
		
		// We start a loop to define the fleet
		// In each loop commander chooses one kind of ship to be added
		// to his fleet
		do {
			System.out.println("Name of the pilot: "); 
			name = reader.nextLine();
			System.out.println("What kind of ship do you want?");
			System.out.println("1.Tie Fleet \n2.Tie Advanced \n3.Tie Bomber \n4.Exit\n");
			option = reader.nextLine();
			
			switch (option) {
			case "1": // a tie fighter
					this.add(new TieFighter(name));
					break;
			case "2":
					this.add(new TieAdvanced(name));
					break;
			case "3":
					this.add(new TieBomber(name));
					break;
			case "4":
					System.out.println("Ended.");
					break;
			default:
					System.out.println("Option incorrect");
			}
		} while(!option.equals("4"));
		
		showFleet();
	}
	
	/**
	 * Show Fleet
	 */
	private void showFleet() {
		for (SpaceShip ship : this) {
			System.out.println("Type: " + ship.type + "," + ship.toString());
		}
	}
	
	/**
	 * Set commander
	 * @param reader
	 */
	private void setCommander(Scanner reader) {
		do {
			System.out.println("Commander name: ");
			commanderName = reader.nextLine();
		} while (commanderName.isEmpty());
	}
}


